import CryptoJS from '@/uni_modules/crypto-js/crypto-js.js'

// AES加密
export const encryptAES = (message) => {
	var key = CryptoJS.enc.Utf8.parse('1234567812345678');
	var iv = CryptoJS.enc.Utf8.parse('1234567812345678');
	var encrypted = CryptoJS.AES.encrypt(message, key, { 
		iv: iv, 
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.toString();
}

// AES解密
export const decryptAES = (encrypted) => {

	var key = CryptoJS.enc.Utf8.parse('1234567812345678');
	var iv = CryptoJS.enc.Utf8.parse('1234567812345678');
	const decrypted =  CryptoJS.AES.decrypt(encrypted, key, { 
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	return decrypted.toString(CryptoJS.enc.Utf8);
}

//简单加密   位移加密
export const encrypt=(text, shift)=> {
  let encryptedText = '';
  for (let i = 0; i < text.length; i++) {
    const char = text.charCodeAt(i);
    encryptedText += String.fromCharCode(char + shift);
  }
  return encryptedText;
}
//简单解密   位移shift 解密
export const decrypt=(encryptedText, shift) =>{
  let decryptedText = '';
  for (let i = 0; i < encryptedText.length; i++) {
    const char = encryptedText.charCodeAt(i);
    decryptedText += String.fromCharCode(char - shift);
  }
  return decryptedText;
}